package com.kaxicore.kaxi.mapper;
import com.kaxicore.kaxi.entity.Staff;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StaffMapper {
    // 查看数据
    @Select("SELECT * FROM tb_staff where del_flag=0 AND staff_name LIKE CONCAT('%', #{name}, '%')")
    public List<Staff> getAllStaffs(String name) throws Exception;

    // 查看单个staff
    @Select("SELECT * FROM tb_staff WHERE staff_id=#{id} AND del_flag=0")
    public Staff getStaffById(Integer id) throws Exception;

    // 更新staff
    @Update("UPDATE tb_staff SET " +
            "staff_name=#{staffName}, gender=#{gender}, birthday=#{birthday}, department=#{department}," +
            "work_city=#{workCity}, phonenumber=#{phoneNumber}, email=#{email}," +
            "salary=#{salary}, role=#{role}, unit=#{unit}, role_function=#{roleFunction}," +
            "staff_status=#{staffStatus}, del_flag=0 WHERE staff_id=#{staffID}")
    public void updateStaff(Staff staff) throws Exception;

    // 新增staff
    @Insert({"INSERT INTO tb_staff(staff_name, gender, birthday, " +
            "phonenumber, email, salary, role, unit, role_function, staff_status, department, work_city,  del_flag) " +
            "VALUES(#{staffName}, #{gender}, #{birthday}, #{phoneNumber}, #{email}, " +
            "#{salary}, #{role}, #{unit}, #{roleFunction}, #{staffStatus}, #{department}, #{workCity}, 0)"})
    @Options(useGeneratedKeys = true, keyProperty = "staffID")
    public void addStaff(Staff staff) throws Exception;

    // 删除staff
    @Delete("UPDATE tb_staff SET del_flag=1, staff_status=0 WHERE staff_id=#{id}")
    public void deleteStaff(Integer id) throws Exception;
}
